/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bookstore.tag;
import bookstore.dao.CategoryDao;
import bookstore.iservice.ICategoryService;
import bookstore.model.Category;
import bookstore.service.CategoryService;
import java.io.IOException;
import java.util.List;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
/**
 *
 * @author Administrator
 */
public class CategoryTagHandler extends SimpleTagSupport {

    @Override
    public void doTag() throws JspException {
        JspWriter out = getJspContext().getOut();
        ICategoryService categoryService = new CategoryService();
        categoryService.setCategoryDao(new CategoryDao());
        List<Category> list = categoryService.findAllCategories();
        StringBuilder sb = new StringBuilder();
        sb.append("<table border=\"0\"  cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" height=\"100%\">");
        sb.append("<tr>");
        for (int i = 0; i < list.size(); i++) {
            Category category = list.get(i);
            sb.append("<td><a href=\"BookAction.action?pageNo=1&categoryId=");
            sb.append(category.getId()).append("\">");
            sb.append(category.getName()).append("</a></td>");
        }
        sb.append("</tr>");
        sb.append("</table>");
        try {
            out.println(sb.toString());
        } catch (IOException ex) {
        }
    }
}
